//+------------------------------------------------------------------+ //| Moving Averages Advance.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. 2007, MQL Service | //| http://www.mqlservice.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp. 2007, MQL Service" #property link "http://www.mqlservice.com/" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue //---- indicator parameters extern int VolP_Period=14; //---- indicator buffers double ExtMapBufferVolP_up[]; double ExtMapBufferVolP_dwn[]; //---- int ExtCountedBars=0; int i, periodbar, objckeckback, objckeckfrwd, frwdbar,backbar; double open, close, barpips, gainpos, volpos, pips, gainneg, volneg, gainratio,barvol; double volratio,gainnet,avpipsperbar,volfactor, volnumberfactor,volpipsfactor, adjustment, adjustmentnorm; double plot1,plot2, totaladjustment, upratio,dwnratio, netratio, net; datetime ObjName;//+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { int draw_begin; string short_name; //---- drawing settings SetIndexStyle(0,DRAW_LINE); //IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); if(VolP_Period<2) VolP_Period=14; draw_begin=VolP_Period-1; //---- indicator short name short_name="VolP("; IndicatorShortName(short_name+VolP_Period+")"); SetIndexDrawBegin(0,draw_begin); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBufferVolP_up); //========================================second buff //---- drawing settings SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(1,draw_begin); //---- indicator buffers mapping SetIndexBuffer(1,ExtMapBufferVolP_dwn); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { if(Bars<=VolP_Period) return(0); ExtCountedBars=IndicatorCounted(); //---- check for possible errors if (ExtCountedBars<0) return(-1); //---- last counted bar will be recounted if (ExtCountedBars>0) ExtCountedBars--; //---- done MA's //double sum=0; double gainpos=0; double volpos=0; double gainneg=0; double volneg=0; int i,pos=Bars-ExtCountedBars-1; //---- initial accumulation if(pos0) {gainpos+=barpips; volpos+=barvol; } if(barpips<0) {gainneg+=barpips; volneg+=barvol; } }//for(i=1;i=0) // { // sum+=Close[pos]; while(pos>=0) { barvol=Volume[pos]; open=Open[pos]; close=Close[pos]; barpips=close-open; if(barpips>0) { gainpos+=barpips; volpos+=barvol; } if(barpips<0) {gainneg+=barpips; volneg+=barvol; } // ExtMapBuffer[pos]=sum/MA_Period; upratio=volpos/gainpos; //up vol per pip dwnratio=volneg/gainneg; //dwn vol per pip double uprationorm=NormalizeDouble(upratio,0); double dwnrationorm=NormalizeDouble(dwnratio,0); ExtMapBufferVolP_up[pos]=(uprationorm); ExtMapBufferVolP_dwn[pos]=(dwnrationorm*(-1)); // sum-=Close[pos+MA_Period-1]; barvol=Volume[pos+VolP_Period-1]; open=Open[pos+VolP_Period-1]; close=Close[pos+VolP_Period-1]; barpips=close-open; if(barpips>0) {gainpos-=barpips; volpos-=barvol; } if(barpips<0) {gainneg-=barpips; volneg-=barvol; } // pos--; // } pos--; }//while //---- zero initial bars //if(ExtCountedBars<1) //for(i=1;i